package com.ims.controller;

import com.ims.form.Public.classoptions.*;
import com.ims.form.Public.majoroptions.*;
import com.ims.repository.StudentInfoRepository;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import java.util.ArrayList;
import java.util.List;

@Api
@RestController
public class PublicController {
    @Autowired
    private StudentInfoRepository studentInfoRepository;

    @ApiOperation(value = "班级过滤器")
    @PostMapping(value = "/classoptions")
    public ClassInfoForm getClassOptions(@RequestBody @ApiParam(value = "选择的专业", required = true) getClassOptionsForm req) {//请求中只有一个参数major
        List<String> classes = studentInfoRepository.findStuclassByMajor(req.getMajor());
        ClassInfoForm classInfoForm = new ClassInfoForm(0, "已获得班级过滤器选项", new ArrayList<String>(classes));
        return classInfoForm;
    }

    @ApiOperation(value = "专业过滤器")
    @PostMapping(value = "/majoroptions")
    public MajorInfoForm getMajorOptions() {
        List<String> majors = studentInfoRepository.findMajor();
        MajorInfoForm majorInfoForm = new MajorInfoForm(0, "已获得专业选项", new ArrayList<String>(majors));
        return majorInfoForm;
    }
}
